package com.guigu.qingcheng.mapper;

import com.guigu.qingcheng.pojo.TbOrder;
import com.guigu.qingcheng.pojo.TbOrderItem;
import com.guigu.qingcheng.pojo.dto.OrderItemSku;
import com.guigu.qingcheng.pojo.vo.CategoryReportVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

public interface TbOrderMapper extends Mapper<TbOrder> {


    /**
     * 订单统计
     * @return
     */
    List<Map> orders(@Param("categoryReportVo") CategoryReportVo categoryReportVo);

    List<TbOrder> pageQueryIdsByAll(@Param("ids") String[] ids);

    /**
     * 查询今日订单总数
     * @param localDate
     * @return
     */
    Map findtodayOrder(@Param("localDate") LocalDate localDate);


    /**
     * 查询订单
      * @return
     */
    Map Queryorderstatus(Integer status);

    /**
     * 自定义方法查询 订单、订单明细、商品表 三表查询 前端我的订单数据
     * @param username
     * @return
     */
    @Select("SELECT o.id,o.create_time createTime,s.name,s.spec,oi.price,o.pre_money preMoney,\n" +
            "    oi.num,o.order_status orderStatus,oi.post_fee postFee,s.image,\n" +
            "    o.pay_status payStatus,o.consign_status consignStatus\n" +
            "    FROM tb_order o INNER JOIN tb_order_item oi ON o.id = oi.order_id\n" +
            "    INNER JOIN qingcheng_goods.tb_sku s ON oi.sku_id = s.id\n" +
            "    WHERE o.is_delete = 0 and o.username = #{username} and o.order_status = #{orderStatus}")
    List<OrderItemSku> queryOrderItemSkuByUsername(String username,Integer orderStatus);

    /**
     * 自定义方法查询 订单、订单明细、商品表 三表查询 前端我的订单数据
     * @param username
     * @return
     */
    @Select("SELECT o.id,o.create_time createTime,s.name,s.spec,oi.price,o.pre_money preMoney,\n" +
            "    oi.num,o.order_status orderStatus,oi.post_fee postFee,s.image,\n" +
            "    o.pay_status payStatus,o.consign_status consignStatus\n" +
            "    FROM tb_order o INNER JOIN tb_order_item oi ON o.id = oi.order_id\n" +
            "    INNER JOIN qingcheng_goods.tb_sku s ON oi.sku_id = s.id\n" +
            "    WHERE o.is_delete = 0 and o.username = #{username}")
    List<OrderItemSku> queryOrderItemSkuByUsernameAll(String username,Integer orderStatus);

    /**
     * 通过订单Id 获取到 订单、订单明细、商品表 三表查询 的数据
     * @param id
     * @return
     */
    @Select("SELECT o.id,o.create_time createTime,s.name,s.spec,oi.price,o.pre_money preMoney,\n" +
            "    oi.num,o.order_status orderStatus,oi.post_fee postFee,s.image,\n" +
            "    o.pay_status payStatus,o.consign_status consignStatus\n" +
            "    FROM tb_order o INNER JOIN tb_order_item oi ON o.id = oi.order_id\n" +
            "    INNER JOIN qingcheng_goods.tb_sku s ON oi.sku_id = s.id\n" +
            "    WHERE o.is_delete = 0 and o.id = #{id}")
    OrderItemSku queryOrderItemSkuByOrderId(String id);
}